package game.source.gui;

import game.source.gui.hud.Hud;
import game.source.gui.menu.GameMenu;
import game.source.gui.menu.MenuCreditos;
import game.source.gui.menu.MenuInstru;

import java.awt.BorderLayout;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.UIManager;


/*Frame da Janela:
 * Classe que inicia a parte gráfica.
 */
public class GameFrame extends JFrame{
	private boolean			pause;
	private GameMenu		gameMenu;
	private MenuCreditos	menuCreditos;
	private MenuInstru 		menuInfo;
	private GamePanel 		gamePanel;

	public GameFrame() {
		try {
			UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
		} catch (Exception e) {
			e.printStackTrace();
		}
		this.setTitle("Air Hunter");
		this.setSize(800, 600);
		this.gameMenu = new GameMenu(this);
		this.setLayout(new BorderLayout());
		this.add(gameMenu, "Center");
		this.pause = false;
		this.addWindowListener(new WindowAdapter() {

			@Override
			public void windowDeactivated(WindowEvent e) {
				super.windowDeactivated(e);
				if(!pause && gamePanel != null){
					Hud.pause();
					pause = true;	
				}
			}
		});
		this.addKeyListener(new KeyAdapter() {

			@Override
			public void keyPressed(KeyEvent e) {
				if(e.getKeyCode() == KeyEvent.VK_P){
					if(gamePanel != null){
						if(pause){
							Hud.play();
							pause = false;
						}else{
							Hud.pause();
							pause = true;
						}
					}
				}
			}
		});
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
		this.setResizable(false);

	}

	public void start() {
		this.setVisible(true);
	}

	public GameMenu getGameMenu() {
		return this.gameMenu;
	}

	public void setGameMenu(GameMenu gameMenu) {
		this.gameMenu = gameMenu;
	}

	public MenuCreditos getMenuCreditos() {
		return this.menuCreditos;
	}

	public void setMenuCreditos(MenuCreditos menuCreditos) {
		this.menuCreditos = menuCreditos;
	}

	public MenuInstru getMenuInfo() {
		return this.menuInfo;
	}

	public void setMenuInfo(MenuInstru menuInfo) {
		this.menuInfo = menuInfo;
	}

	public GamePanel getGamePanel() {
		return this.gamePanel;
	}

	public void setGamePanel(GamePanel gamePanel) {
		this.gamePanel = gamePanel;
	}
}
